package com.ponhu.ea2.stockcenter.provider.service.entity.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ponhu.ea2.stockcenter.provider.entity.GWallWareHouseStock;
import com.ponhu.ea2.stockcenter.provider.mapper.GWallStockMapper;
import com.ponhu.ea2.stockcenter.provider.service.entity.GWallStockService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class GWallStockServiceImpl
        extends ServiceImpl<GWallStockMapper, GWallWareHouseStock>
        implements GWallStockService {

    @Override
    public List<GWallWareHouseStock> getGWallStockList(String warehouseCode, List<String> inventoryCodes) {
        LambdaQueryWrapper<GWallWareHouseStock> queryWrapper = Wrappers
                .lambdaQuery(GWallWareHouseStock.class)
                .groupBy(GWallWareHouseStock::getWarehouseCode, GWallWareHouseStock::getInventoryCode);

        if (CollectionUtils.isNotEmpty(inventoryCodes))
            queryWrapper.in(GWallWareHouseStock::getInventoryCode, inventoryCodes);

        if (StringUtils.isNotBlank(warehouseCode))
            queryWrapper.eq(GWallWareHouseStock::getWarehouseCode, warehouseCode);

        return list(queryWrapper);
    }

}




